﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace reminder_csh.Entities {
    public class MyDbContext : DbContext {
        public virtual DbSet<Task> TaskDbSet {
            get;
            set;
        }
        public virtual DbSet<Worker> WorkerDbSet {
            get;
            set;
        }

        public MyDbContext() : base(@"Data Source=(localdb)\v11.0;Initial Catalog=ReminderDBForms;Integrated Security=True") {
        }
        public MyDbContext(string nameOrConnectionString)
            : base(nameOrConnectionString) {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Worker>().HasMany(x => x.Tasks).WithMany(x => x.Workers).Map(x =>
            {
                x.ToTable("WorkerTasks");
                x.MapLeftKey("WorkerId");
                x.MapRightKey("TaskId");
            });
            base.OnModelCreating(modelBuilder);
        }
    };
}
